// Explore API client for Exploration Mode (new backend under /api/explore)
import api from './http'

export const exploreApi = {
  // Nodes
  listNodes(params = {}) {
  return api.get('/api/explore/nodes', { params })
  },
  getNode(nodeId) {
  return api.get(`/api/explore/nodes/${nodeId}`)
  },
  getNodeQuests(nodeId) {
  return api.get(`/api/explore/nodes/${nodeId}/quests`)
  },

  // Quest lifecycle
  startQuest(questId) {
  return api.post(`/api/explore/quests/${questId}/start`)
  },
  reportProgress(questId, progress) {
    // Accept legacy { seconds } or new shape { payload: { elapsed } }
    let body = progress || {}
    if ('seconds' in body && !('payload' in body)) {
      body = { payload: { elapsed: body.seconds } }
    }
  return api.post(`/api/explore/quests/${questId}/progress`, body)
  },
  finishQuest(questId, payload = {}) {
    // payload may include proof or context; finish validates requirement server-side
  return api.post(`/api/explore/quests/${questId}/finish`, payload)
  },

  // User
  userSummary() {
  return api.get('/api/explore/user/summary')
  },

  // Lore
  getLore(nodeId) {
  return api.get(`/api/explore/nodes/${nodeId}/lore`)
  },
  refreshLore(nodeId, force = false) {
  return api.post(`/api/explore/nodes/${nodeId}/lore/refresh`, { force })
  },

  // Achievements
  achievements() {
  return api.get('/api/explore/achievements')
  }
}

export default exploreApi
